package zaplog

import (
	"HeadLineNews/utils/gin_ctx"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"strings"
)

// Fields 日志定制需要哪些字段
func Fields(c *gin.Context, params interface{}, detail interface{}) (fields []zap.Field) {
	handler := c.HandlerName()[strings.LastIndex(c.HandlerName(), "/")+1:]
	fields = append(fields, zap.String("handlerName", handler))                  // 句柄
	fields = append(fields, zap.Any("detail", detail))                           // 具体（报错）信息
	fields = append(fields, zap.Any("params", params))                           // 参数
	fields = append(fields, zap.String("createBy", c.GetString(gin_ctx.UserId))) // 日志发起者ID
	fields = append(fields, zap.String("clientIP", c.ClientIP()))                // 客户端IP
	return
}
